<?php

$pathnew = dirname(__FILE__) . '/node_modules';
chdir( dirname(__FILE__) . '/../../../www/lib' );

$packages = array(
    'chart.js'     => array(
        'copy' => array(
            'chart.js/dist/Chart.bundle.min.js' => 'chart.js/Chart.bundle.min.js',
            'chart.js/LICENSE.md' => 'chart.js/LICENSE.md',
        ),
    ),
    'font-awesome' => array(
        'copy' => array( 
            'font-awesome/css/font-awesome.css'            => 'font-awesome/css/font-awesome.css',
            'font-awesome/css/font-awesome.css.map'        => 'font-awesome/css/font-awesome.css.map',
            'font-awesome/css/font-awesome.min.css'        => 'font-awesome/css/font-awesome.min.css',
            'font-awesome/README.md'                       => 'font-awesome/README.md',
            'font-awesome/fonts/FontAwesome.otf'           => 'font-awesome/fonts/FontAwesome.otf',
            'font-awesome/fonts/fontawesome-webfont.eot'   => 'font-awesome/fonts/fontawesome-webfont.eot',
            'font-awesome/fonts/fontawesome-webfont.svg'   => 'font-awesome/fonts/fontawesome-webfont.svg',
            'font-awesome/fonts/fontawesome-webfont.ttf'   => 'font-awesome/fonts/fontawesome-webfont.ttf',
            'font-awesome/fonts/fontawesome-webfont.woff'  => 'font-awesome/fonts/fontawesome-webfont.woff',
            'font-awesome/fonts/fontawesome-webfont.woff2' => 'font-awesome/fonts/fontawesome-webfont.woff2',
        ),
    ),
    'jquery' => array(
        'copy' => array(
            'jquery/LICENSE.txt'         => 'jquery/LICENSE.txt',
            'jquery/dist/jquery.min.js'  => 'jquery/jquery.min.js',
            'jquery/dist/jquery.min.map' => 'jquery/jquery.min.map',
        ),
    ),
    'jquery-ui-dist' => array(
        'copy' => array(
            'jquery-ui-dist/LICENSE.txt'        => 'jquery-ui/LICENSE.txt',
            'jquery-ui-dist/jquery-ui.min.css'  => 'jquery-ui/jquery-ui.min.css',
            'jquery-ui-dist/jquery-ui.min.js'   => 'jquery-ui/jquery-ui.min.js',
            'jquery-ui-dist/jquery-ui.structure.min.css'   => 'jquery-ui/jquery-ui.structure.min.css',
            'jquery-ui-dist/jquery-ui.theme.min.css'       => 'jquery-ui/jquery-ui.theme.min.css',
            'jquery-ui-dist/images/ui-icons_444444_256x240.png' => 'jquery-ui/images/ui-icons_444444_256x240.png',
            'jquery-ui-dist/images/ui-icons_555555_256x240.png' => 'jquery-ui/images/ui-icons_555555_256x240.png',
            'jquery-ui-dist/images/ui-icons_777620_256x240.png' => 'jquery-ui/images/ui-icons_777620_256x240.png',
            'jquery-ui-dist/images/ui-icons_777777_256x240.png' => 'jquery-ui/images/ui-icons_777777_256x240.png',
            'jquery-ui-dist/images/ui-icons_cc0000_256x240.png' => 'jquery-ui/images/ui-icons_cc0000_256x240.png',
            'jquery-ui-dist/images/ui-icons_ffffff_256x240.png' => 'jquery-ui/images/ui-icons_ffffff_256x240.png',
        ),
    ),
    'promise-polyfill' => array(
        'copy' => array(
            'promise-polyfill/LICENSE'           => 'promise-polyfill/LICENSE',
            'promise-polyfill/dist/polyfill.min.js'  => 'promise-polyfill/polyfill.min.js',
            
        ),
    ),
    'webcrypto-shim' => array(
        'copy' => array(
            'webcrypto-shim/LICENSE'                    => 'webcrypto-shim/LICENSE',
            'webcrypto-shim/webcrypto-shim.min.js'      => 'webcrypto-shim/webcrypto-shim.min.js',
            'webcrypto-shim/webcrypto-shim.min.js.map'  => 'webcrypto-shim/webcrypto-shim.min.js.map',
            
        ),
    ),
    'xregexp' => array(
        'copy' => array(
            'xregexp/LICENSE'                        => 'xregexp/LICENSE',
            'xregexp/xregexp-all.js'                 => 'xregexp/xregexp-all.js',
        ),
    ),



);


$verbose = 1;



foreach( $packages as $pkg => $d ) {
    echo "Copying package $pkg\n";
    foreach( $d['copy'] as $srcpath => $dstpath ) {
        if( $verbose ) {
            echo "   Copying $srcpath to $dstpath \n";
        }
        if (!is_dir(dirname($dstpath))) {
            mkdir(dirname($dstpath), 0777, true);
        }
        copy( $pathnew . '/' . $srcpath, $dstpath );
    }
}
